package ar.com.angrymachine.hunter.ui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.HunterResourceManager;
import ar.com.angrymachine.gameui.Utils;
import ar.com.angrymachine.gameui.Widget;

public class LabelWidget extends Widget
{
    private Color background,text;
    
    public LabelWidget(Widget parent, Rectangle area, Color background, Color text)
    {
        super(parent, area);
        this.background = background;
        this.text = text;
    }
    
    private String retrieveLabel()
    {
        String label = "";
        if(Game.current != null)
        {
        	label = Game.current.getZoneDescription();
        }
        return label;    	
    }
    
    public void paint(Graphics g)
    {
        // background
        g.setFont(HunterResourceManager.activityLabelFont);
        g.setColor(background);
        g.fillRect(0, 0, getWidth(), getHeight());
        String label = retrieveLabel();
        if(label.length() > 0)
        {
            // center the text horizontally
            Point textSize = Utils.stringSize(g, label);
            int startX = (getWidth() - textSize.x)/2;
            // vertically
            g.setColor(text);
            Utils.drawStringVerticallyCentered(g, label, startX, getHeight()/2);
        }
        g.setColor(Color.GRAY);
        g.drawLine(0, getHeight() - 1, getWidth(),getHeight() - 1);
    }
}
